package cn.iocoder.yudao.module.wine.controller.app.stockinfoitem;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.app.stockinfoitem.vo.*;
import cn.iocoder.yudao.module.wine.dal.dataobject.stockinfoitem.StockInfoitemDO;
import cn.iocoder.yudao.module.wine.service.stockinfoitem.StockInfoitemService;

@Tag(name = "用户 APP - 出入库信息项")
@RestController
@RequestMapping("/wine/stock-infoitem")
@Validated
public class AppStockInfoitemController {

    @Resource
    private StockInfoitemService stockInfoitemService;

    @PostMapping("/create")
    @Operation(summary = "创建出入库信息项")
    public CommonResult<Long> createStockInfoitem(@Valid @RequestBody AppStockInfoitemSaveReqVO createReqVO) {
        return success(stockInfoitemService.appCreateStockInfoitem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新出入库信息项")
    public CommonResult<Boolean> updateStockInfoitem(@Valid @RequestBody AppStockInfoitemSaveReqVO updateReqVO) {
        stockInfoitemService.appUpdateStockInfoitem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除出入库信息项")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteStockInfoitem(@RequestParam("id") Long id) {
        stockInfoitemService.appDeleteStockInfoitem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得出入库信息项")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppStockInfoitemRespVO> getStockInfoitem(@RequestParam("id") Long id) {
        StockInfoitemDO stockInfoitem = stockInfoitemService.getStockInfoitem(id);
        return success(BeanUtils.toBean(stockInfoitem, AppStockInfoitemRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得出入库信息项列表")
    public CommonResult<List<AppStockInfoitemRespVO>> getStockInfoitemList(@Valid AppStockInfoitemPageReqVO reqVO) {
        List<StockInfoitemDO> list = stockInfoitemService.getStockInfoitemList(reqVO);
        return success(BeanUtils.toBean(list, AppStockInfoitemRespVO.class));
    }

}
